package com.example.controller;

import com.example.common.Result;
import com.example.entity.User;
import com.example.entity.Volunteer;
import com.example.service.VolunteerService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * 志愿者模块前端请求的端口
 */
@RestController
@RequestMapping("/volunteer")
public class VolunteerController {

    @Resource
    private VolunteerService volunteerService;
/*
* 新增
*
*
* */

    @PostMapping("/add")
    public Result add(@RequestBody  Volunteer volunteer){
        volunteerService.add(volunteer);

     return Result.success();
    }

    /*
    * 更新
    * */
    @PutMapping("/update")
    public Result update(@RequestBody Volunteer volunteer) {
        volunteerService.updateById(volunteer);
        return Result.success();
    }

    /*
     * 删除
     * */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        volunteerService.deleteById(id);
        return Result.success();
    }
    /*
    * 查询所有
    * */
    @GetMapping("/selectAll")
    public Result selectAll(Volunteer volunteer){
        List<Volunteer> list=volunteerService.selectAll();
        return Result.success(list);
    }

    /*
     * 个人资料查询
     * */

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Volunteer volunteer =  volunteerService.selectById(id);
        return Result.success(volunteer);
    }



    /**
 *
 * 分页查询
 */
@GetMapping("/selectPage")
public Result selectPage(Volunteer volunteer,
                         @RequestParam(defaultValue = "1") Integer pageNum,
                         @RequestParam(defaultValue = "5") Integer pageSize) {
    PageInfo<Volunteer> pageInfo = volunteerService.selectPage(volunteer, pageNum, pageSize);
    return Result.success(pageInfo);
}
}
